﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Pg.BioMedics.SDR.Data
{
    /// <summary>
    /// Data context for all SDR data managers
    /// </summary>
    public class SDRDataContext : BaseDataContext
    {
        #region Fields

        private PersonManager personManager;
        private ContentManager contentManager;
        private DocumentManager documentManager;
        private AnnotationManager annotationManager;
        private SearchManager searchManager;

        #endregion

        #region Constructors

        /// <summary>
        /// Creates instance of SDRDataContext. All required configuration data 
        /// are loaded from configuration file section or set as defaults 
        /// if the section does not exist.
        /// </summary>
        public SDRDataContext()
            : base() { }

        /// <summary>
        /// Creates instance of SDRDataContext for given connection string.
        /// The instance support for transaction is enabled if transactions 
        /// parameter is set to true.
        /// </summary>
        /// <param name="connectionString">Connection string for SDR datbase</param>
        /// <param name="transactions">Defines if data context should operate in transaction mode</param>
        public SDRDataContext(string connectionString, bool transactions)
            : base(connectionString, transactions) { }

        /// <summary>
        /// Creates instance of SDRDataContext. Instance of SDRDataContext
        /// supports or unsupports transactions depending on transactions parameter 
        /// value.
        /// </summary>
        /// <param name="transactions">Defines if data context should operate in transaction mode</param>
        public SDRDataContext(bool transactions)
            : base(transactions) { }

        #endregion

        #region Properties

        /// <summary>
        /// Gets PersonManager initialized in this context. This property supports lazy initialization.
        /// </summary>
        public virtual PersonManager PersonManager
        {
            get
            {
                if (this.personManager == null)
                    this.personManager = new PersonManager(DataMapperStrategy);

                return this.personManager;
            }
        }

        /// <summary>
        /// Gets ContentManager initialized in this context. This property supports lazy initialization.
        /// </summary>
        public virtual ContentManager ContentManager
        {
            get
            {
                if (this.contentManager == null)
                    this.contentManager = new ContentManager(DataMapperStrategy);

                return this.contentManager;
            }
        }

        /// <summary>
        /// Gets DocumentManager initialized in this context. This property supports lazy initialization.
        /// </summary>
        public virtual DocumentManager DocumentManager
        {
            get
            {
                if (this.documentManager == null)
                    this.documentManager = new DocumentManager(DataMapperStrategy);

                return this.documentManager;
            }
        }

        /// <summary>
        /// Gets AnnotationManager initialized in this context. This property supports lazy initialization. 
        /// </summary>
        public virtual AnnotationManager AnnotationManager
        {
            get
            {
                if (this.annotationManager == null)
                    this.annotationManager = new AnnotationManager(DataMapperStrategy);

                return this.annotationManager;
            }
        }

        /// <summary>
        /// Gets SearchManager initialized in this context. This property supports lazy initialization.
        /// </summary>
        public virtual SearchManager SearchManager
        {
            get
            {
                if (this.searchManager == null)
                    this.searchManager = new SearchManager(DataMapperStrategy);

                return this.searchManager;
            }
        }

        #endregion
    }
}
